package acwing._1_1AlgorithmBasic._6Greedy;
/**
 * @Project : AlgorithmLearning
 * @Package : ACWing._1_1AlgorithmBasic._6Greedy
 * @File : Q0908.java
 * @Author : WangRuoyu
 * @Date : 2023/4/7 9:26
 */

import java.io.*;
import java.util.Arrays;

public class Q0908 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String[] words = br.readLine().split(" ");
        int n = Integer.parseInt(words[0]);
        int[][] s = new int[n][2];
        for (int i = 0; i < n; ++i) {
            words = br.readLine().split(" ");
            int l = Integer.parseInt(words[0]);
            int r = Integer.parseInt(words[1]);
            s[i][0] = l;
            s[i][1] = r;
        }
        Arrays.sort(s, (o1, o2) -> o1[1] != o2[1] ? o1[1] - o2[1] : o1[0] - o2[0]);
        int l = Integer.MIN_VALUE;
        int r = Integer.MIN_VALUE + 1;
        int cnt = 0;
        for (int i = 0; i < n; ++i) {
            l = Math.max(l, s[i][0]);
            if (l > r) {
                cnt++;
                r = s[i][1];
            }
        }
        System.out.println(cnt);
    }
}